package leetcode.review;

import org.junit.Test;

import java.util.Stack;

/**
 * @author :songyaozhang
 * @date :Created 2021/9/2 15:18
 * @description :
 */
public class Main {


  @Test
  public void test() {
    Solution solution = new Solution();
    System.out.println(solution.validateStackSequences(new int[]{}, new int[]{}));
  }

  class Solution {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
      Stack<Integer> stack = new Stack<>();
      int len = pushed.length;
      int index = 0;
      for (int i = 0; i < len; i++) {
        while (!stack.isEmpty() && stack.peek() == popped[index]) {
          stack.pop();
          index++;
        }
        stack.push(pushed[i]);
      }
      while (!stack.isEmpty() && stack.peek() == popped[index]) {
        stack.pop();
        index++;
      }
      return stack.isEmpty();
    }
  }

}
